CUDA = "0" # 虚拟GPU号 0~3
META = "0" # 1 要 META
MLDG = '0'
d = 'mse'
kl = 3e-3
recon = 0.5
alpha = 0.7
REPEAT = 1 # 实验重复次数
V = "../tsne_result"
# models = ['resnet',"tripleattention","dualattention","mtsdnet","transformer",'gile', 'rsc','gruinc','elk']
models = ['resnet']
for BASELINE in models:
    datasets = [
         ("pamap2","128", "512", 8),
         ("unimib_shar","151","256", 4),
         ("opportunity", "64", "512", 4), 
         ("dsads", "125", "512", 8)
    ]
    for i, dataset in enumerate(datasets):
        dataset_dict = eval(open("./data/dataset_dict.json", "r+").read())
        params =   {"dataset_name":"" ,  "model_name":"caonima" ,  "sliding_window_length": "" ,  "batch_size":"" ,  "epochs":"10" ,  "cuda_device":CUDA ,  "use_meta":META, "repeat": REPEAT, "beta":"0", "gamma":"0.5", "save_path":V, 'use_mldg': MLDG, 'd':'mse', 'recon_weight':recon, 'kl_weight':kl, 'alpha': alpha} 
        params['model_name'] = BASELINE
        params["dataset_name"],  params['sliding_window_length'] , params['batch_size'], num_volunteers = dataset
        

        def split_generator(num_volunteers, use_meta):
            
            volunteer_splits = []
        # 1,2,3\|4
            use_meta = int(use_meta)
            if use_meta == 0:
                for i in range(1, num_volunteers+1):
                    
                    temp = f""
                    for j in range(1, num_volunteers+1):
                        
                        if j == i:
                            continue
                        temp += f"{j},"
                    temp = temp[:-1]
                    temp += f"\\|{i}"
                    volunteer_splits.append(temp)
            if use_meta == 1:
                for i in range(1, num_volunteers+1):
                    
                    temp = "\\|"
                    all_temp = ""
                    for j in range(1, num_volunteers+1):
                        
                        if j == i:
                            continue
                        temp += f"{j}\\|"
                        all_temp += f",{j}"
                    temp = temp[:-2]
                    all_temp = all_temp[1:]
                    temp += f"\\|{i}"
                    res = all_temp + temp # resnetvae
                    # res = temp[2:] # resnetvae
                    volunteer_splits.append(res)
                    
            return volunteer_splits

        results = []

        volunteer_splits = split_generator(num_volunteers, params["use_meta"])
        for volunteer_split in volunteer_splits:
            result = "python main.py "
            for key,value in params.items():
                result += f"--{key} {value} "
            result += f"--volunteer_split {volunteer_split} "
            
            result += f"--n_domains {num_volunteers} "
            results.append(result)
            print(result)
            break
            

        with open(f"./scripts/meta_cuda{params['cuda_device']}.sh", mode="a+", encoding="utf-8") as f:
            
            print(f"{params['dataset_name']}_cuda{params['cuda_device']}")    
            for r in results:
                f.write(r + "\n\n")
